db_config = YAML.load_file("#{Rails.root}/config/mongo.yml")
mongo = db_config[Rails.env]
MongoMapper.connection = Mongo::Connection.new(mongo['host'], mongo['port'])
MongoMapper.database = mongo['database']

if mongo['username'] && mongo['password']
  MongoMapper.database.authenticate(mongo['username'], mongo['password'])
end

if defined?(PhusionPassenger)
  PhusionPassenger.on_event(:starting_worker_process) do |forked|
    MongoMapper.connection.connect if forked
  end
end